﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Organizer.ViewModel;
using Organizer.Model;

namespace Organizer
{
    public partial class TaskListPage : PhoneApplicationPage
    {

        TaskListPageVM _viewModel;

        public TaskListPageVM ViewModel
        {
            get { return _viewModel; }           
        }

        public TaskListPage()
        {
            InitializeComponent();

            _viewModel = new TaskListPageVM();
            DataContext = _viewModel;
        }

        protected void EditTask()
        {
            //редактирование таска

            if (listBoxTasks.SelectedItem != null)
            {
                string destination = "/TaskEdit";

                destination += String.Format("?TaskId={0}", ((Task)listBoxTasks.SelectedItem).Id);
                NavigationService.Navigate(new Uri(destination, UriKind.Relative));
            }
        }

        protected void AddNewTask()
        {
            //новый таск
            string destination = "/TaskEdit";
            destination += String.Format("?TaskId={0}", "null");
            NavigationService.Navigate(new Uri(destination, UriKind.Relative));
        }


        private void appBtnAddTask_Click(object sender, EventArgs e)
        {
            AddNewTask();
        }        

        private void appBtnDelTask_Click(object sender, EventArgs e)
        {
            //удалить таск

        }

        private void appBtnEditTask_Click(object sender, EventArgs e)
        {
            EditTask();
        }

        private void listBoxTasks_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            
            EditTask();
        }
    }
}